package zuoye;

import util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class Menujpanel extends JPanel implements ActionListener {
    private JButton SavejButton;
    private Icon saveimage = Util.getIcon("/images/buttonSave.jpg");
    private JButton GetjButton;
    private Icon getimage = Util.getIcon("/images/buttonGet.jpg");
    private JButton FindjButton;
    private Icon findimage = Util.getIcon("/images/buttonFind.jpg");
    private JButton OffjButton;
    private Icon offimage = Util.getIcon("/images/buttonOff.jpg");
    private JButton transferButton;
    private Icon transferimage = Util.getIcon("/images/pane.jpg");
    private JButton modifyButton;
    private Icon modifyimage = Util.getIcon("/images/buttonModify.jpg");
    private Mainjframe frame;

    public Menujpanel(Mainjframe frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        SavejButton = new JButton(saveimage);
        SavejButton.setBounds(0, 50, 140, 50);
        this.add(SavejButton);
        SavejButton.addActionListener(this);

        GetjButton = new JButton(getimage);
        GetjButton.setBounds(0, 350, 140, 50);
        this.add(GetjButton);
        GetjButton.addActionListener(this);

        FindjButton = new JButton(findimage);
        FindjButton.setBounds(0, 650, 140, 50);
        this.add(FindjButton);
        FindjButton.addActionListener(this);

        modifyButton = new JButton(modifyimage);
        modifyButton.setBounds(1045, 50, 140, 50);
        this.add(modifyButton);
        modifyButton.addActionListener(this);

        transferButton = new JButton("转账");
        transferButton.setForeground(Color.BLACK);
        transferButton.setFont(new Font("宋体",Font.BOLD,22));
        transferButton.setBounds(1045, 350, 140, 50);
        this.add(transferButton);
        transferButton.addActionListener(this);

        OffjButton = new JButton(offimage);
        OffjButton.setBounds(1045, 650, 140, 50);
        this.add(OffjButton);
        OffjButton.addActionListener(this);


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == SavejButton) {
            frame.switchPanel("Save");
        } else if (e.getSource() == GetjButton) {
            frame.switchPanel("Get");
        } else if (e.getSource() == FindjButton) {
            frame.switchPanel("Find");
            List<User> user = frame.getG().query();
            frame.getFindjpanel().getjLabel1().setText(user.get(frame.getIndex()).getMoney() + "");
        } else if (e.getSource() == transferButton){
            frame.switchPanel("Transfer");
        } else if (e.getSource() == modifyButton){
            frame.switchPanel("Modify");
        } else if (e.getSource() == OffjButton){
            frame.getLoginjpanel().setConut(3);
            frame.switchPanel("login");
        }
    }
}
